﻿<cfsilent>
	<cfscript>

		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");

		termId = event.getArg("TermID");
		depId = event.getArg("DepID");

		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		sql = "	SELECT
					i.institute_short,
					i.institute_name
				FROM
					t_institute i
				WHERE
					i.institute_id = :instituteId ";

		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "instituteId", value = depId, cfsqltype = "cf_sql_varchar");
		rs_instituteEntity = queryObj.execute(sql = sql).getResult();

		event.setArg("pageTitle", "教材管理 - 教材征订与发放 - 学期征订计划 - " & rs_instituteEntity.institute_short);
		
		currentTab = event.getArg("TabID", "labBookPlan");
		
		targetArgs = structNew();

		structInsert(targetArgs, "DepID", depId, true);
		
		/* 学院征订计划 */
		sql = "	SELECT
					cb.cbid,
					c.course_name,
					b.book_name,b.book_authors,b.book_edition,p.publisher,
					cb.plan_student,cb.plan_teacher,
					c.cid,
					b.bid,
					CASE WHEN cb.contract IS NULL THEN '-' ELSE cb.contract END contract,
					CASE WHEN cb.telephone IS NULL THEN '-' ELSE cb.telephone END telephone
				FROM
					t_course_book cb INNER JOIN t_course c ON cb.cid = c.cid INNER JOIN t_book b ON cb.bid = b.bid INNER JOIN t_publisher p ON b.pid = p.pid
					INNER JOIN t_institute i ON i.institute_id = c.institute_id
				WHERE
					cb.term_id = :termId AND i.institute_id = :depId 
				ORDER BY
					c.course_name";

		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
		queryObj.addParam(name = "depId", value = depId, cfsqltype = "cf_sql_varchar");
		rs_plan = queryObj.execute(sql = sql).getResult();

		courseArray = [];
		bookArray = [];
		
		for( a = 1; a le rs_plan.recordCount; a++ ){
			
			book = [rs_plan["bid"][a], rs_plan["book_name"][a], rs_plan["book_authors"][a], rs_plan["book_edition"][a], [rs_plan["publisher"][a]]];
			course = [rs_plan["cid"][a],rs_plan["course_name"][a]];
			
			if ( not arrayFind(bookArray, book) ) { arrayAppend(bookArray, book); }
			if ( not arrayFind(courseArray, course) ) { arrayAppend(courseArray, course); }
			
		}
		
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('bookPlan')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">学期征订计划</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i>教材征订计划 - <cfoutput>#academicYear#</cfoutput><cfoutput>#dictAdvice.getTerm(academicTerm)#</cfoutput> - <cfoutput>#rs_instituteEntity.institute_name#</cfoutput>
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="programCourse">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labBookPlan">class="active"</cfif> id="labBookPlan" tabTarget="BookPlan">教材征订数据</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					
					// -->
					//]]>
				</script>
				
				<div id="BookPlan" class="tabContent">
					
					<div class="noticeBlock">
						<div class="operation">
							<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('departmentPlanDownloadExcel', targetArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载学院征订计划</span></a>
						</div>
						<h3><cfoutput>#rs_instituteEntity.institute_short#</cfoutput>学院 教材征订计划</h3>
						<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期, <cfoutput>#rs_instituteEntity.institute_name#</cfoutput>计划开设<em><cfoutput>#arrayLen(courseArray)#</cfoutput></em>门课程, 需征订<em><cfoutput>#arrayLen(bookArray)#</cfoutput></em>种教材</p>
					</div>
					
					<table id="cleanList" class="UIEditable">
						<thead>
							<tr>
								<td width="18"></td>
								<td>课程</td>
								<td>书名</td>
								<td>作者</td>
								<td width="50">征订数量</td>
								<td width="50">联系人</td>
								<td width="18"></td>
							</tr>
						</thead>
						<tbody>
							<cfset row = 0 />
                            <cfloop query="rs_plan">
								<cfset row++ />
								<cfset structInsert(targetArgs, "CBID", rs_plan.cbid, true) />
								<cfset structInsert(targetArgs, "CID", rs_plan.cid, true) />
								<cfset structInsert(targetArgs, "BID", rs_plan.bid, true) />
								<tr class="editRows" rowid="<cfoutput>#rs_plan.cbid#</cfoutput>">
									<td class="index"><cfoutput>#row#</cfoutput></td>
									<td nowrap="nowrap"><cfoutput>#rs_plan.course_name#</cfoutput></td>
									<td>《<cfoutput>#rs_plan.book_name#</cfoutput>》<br/><span class="description"><cfoutput>#rs_plan.publisher#</cfoutput> - <cfoutput>#dictAdvice.getBookEdition(rs_plan.book_edition,'')#</cfoutput></span></td>
									<td nowrap="nowrap"><cfoutput>#left(listFirst(rs_plan.book_authors, "/"), 4)#</cfoutput><cfif len(listFirst(rs_plan.book_authors, "/")) gt 4 or listLen(rs_plan.book_authors, "/") gt 1>...</cfif></td>
									<td align="center"><span class="numeric"><cfoutput>#rs_plan.plan_student#</cfoutput>/<cfoutput>#rs_plan.plan_teacher#</cfoutput></span></td>
									<td><span class="numeric"><cfoutput>#rs_plan.telephone#</cfoutput></span><br/><span class="description"><cfoutput>#rs_plan.contract#</cfoutput></span></td>
									<td><a href="<cfoutput>#buildURL('courseBookDetail', targetArgs)#</cfoutput>" class="stat info"></a></td>
								</tr>
							</cfloop>
						</tbody>
					</table>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>